#!/bin/bash
# Filename:      conkytoggleflux.sh
# Purpose:       toggle conky on/off from fluxbox menu
# Authors:       Kerry and anticapitalista, secipolla for antiX
# Authors:       modified for mx linux version 17 by dolphin oracle
# Latest change: Sun December 10, 2017.
# https://github.com/MX-Linux/conky-toggle-mx
# Adapted to work on ArcoLinux
# Author: Erik Dubois
# June 2019
################################################################################

main()
{
if pidof conky | grep [0-9] > /dev/null
 then
  killall conky
  autostart_off
 else
    test=$(grep -q "conky -c" /home/$USER/.config/conky/conky-sessionfile && echo $?)
    if [ "$test" = "0" ]; then
         launch_conky
         autostart_on
    else
    am-conkyzen &
    fi
fi
}

launch_conky()
{
sh am-conky-session &
}

autostart_off()
{

if [ -e /home/$USER/.config/autostart/am-conky-session.desktop ]; then
    sed -i -r s/Hidden=.*/Hidden=true/ /home/$USER/.config/autostart/am-conky-session.desktop
fi

}

autostart_on()
{

if [ -e /home/$USER/.config/autostart/am-conky-session.desktop ]; then
  if ! grep -q "Hidden" /home/$USER/.config/autostart/am-conky-session.desktop
    then
      echo  "Hidden=false" | tee -a /home/$USER/.config/autostart/am-conky-session.desktop
    else
      sed -i -r s/Hidden=.*/Hidden=false/ /home/$USER/.config/autostart/am-conky-session.desktop
  fi
else
	echo '[Desktop Entry]
Comment=
Encoding=UTF-8
Exec=am-conky-session
Name=am-conky-session
StartupNotify=false
Terminal=false
Type=Application
Version=0.9.4
Hidden=false' >> /home/$USER/.config/autostart/am-conky-session.desktop


fi

}

main
exit 0
